///###############
//FILE          : FamilyTester.java
//WRITER        : Lior Zimmerman, liorz06, 066462300
//WRITER        : Ohad Dan, ohad_dan, 036767960
//EXERCISE      : oop ex1 2008
//DESCRIPTION   : This file is the tester class for the FamilyTree class
//###############

package oop.ex1;
import java.util.List;

import oop.ex1.family.*;
import oop.ex1.sortedStructure.SortedListFactory;
import oop.ex1.sortedStructure.SortedStructureFactory;
import oop.ex1.util.InvalidDateException;
import oop.ex1.util.MyDate;

/**
 * A tester for FamilyMember class.
 */
public class FamilyTester {
	
	//Data members.
    static SortedStructureFactory <String, FamilyMember> 
    ssf = new SortedListFactory<String, FamilyMember>();
    static FamilyTree familyTree = new FamilyTree(ssf);
		
	/**
	 * Creates 10 family members and insert them to the tree.
	 */
	public static void setFamilyMemebrs(){
		try{
			FamilyMember fmr0 = new FamilyMember("Zoro",
					FamilyMember.Sex.MALE, new MyDate("01/02/1930"));   
			FamilyMember fmr1 = new FamilyMember("Adam",
					FamilyMember.Sex.MALE, new MyDate("02/03/1940"));
	        FamilyMember fmr2 = new FamilyMember("Beni",
	        		FamilyMember.Sex.MALE, new MyDate("03/04/1950"));   
	        FamilyMember fmr3 = new FamilyMember("Coni",
	        		FamilyMember.Sex.MALE, new MyDate("04/05/1960"));
	        FamilyMember fmr4 = new FamilyMember("David",
	        		FamilyMember.Sex.MALE, new MyDate("05/06/1970"));
	        FamilyMember fmr5 = new FamilyMember("Efrat",
	        		FamilyMember.Sex.FEMALE, new MyDate("07/08/1980"));
	        FamilyMember fmr6 = new FamilyMember("Fruma",
	        		FamilyMember.Sex.FEMALE, new MyDate("09/10/1990"));   
	        FamilyMember fmr7 = new FamilyMember("Gina",
	        		FamilyMember.Sex.FEMALE, new MyDate("01/02/2000"));
	        FamilyMember fmr8 = new FamilyMember("Hana",
	        		FamilyMember.Sex.FEMALE, new MyDate("02/03/2001"));	
	        FamilyMember fmr9 = new FamilyMember("Irena",
	        		FamilyMember.Sex.FEMALE, new MyDate("11/11/2002"));
	        FamilyMember fmr10 = new FamilyMember( "Zina",
	                FamilyMember.Sex.FEMALE, new MyDate("02/02/2001"));
	        
	      //Insert all family member into the sorted family tree.
	        familyTree.insert(fmr0);
	        familyTree.insert(fmr1);
	        familyTree.insert(fmr2);
	        familyTree.insert(fmr3);
	        familyTree.insert(fmr4);
	        familyTree.insert(fmr5);
	        familyTree.insert(fmr6);
	        familyTree.insert(fmr7);
	        familyTree.insert(fmr8);
	        familyTree.insert(fmr9); 
	        familyTree.insert(fmr10);
	        
	      //Set family relations.
	        fmr1.getMarried(fmr9);//Test1
	        fmr8.getMarried(fmr2);
	        fmr0.setFather(fmr1);//Test2
	        fmr0.setMother(fmr9);
	        fmr3.setFather(fmr1);//Test3
	        fmr3.setMother(fmr9);
	        fmr4.getMarried(fmr6);
	        fmr5.setFather(fmr4);
	        fmr5.setMother(fmr6);
	        fmr9.setMother(fmr6);
	        fmr8.setMother(fmr6);
	        fmr7.setMother(fmr6);
	        fmr10.setMother(fmr6);
	        fmr10.setFather(fmr4);
	        List<FamilyMember> elders = familyTree.findElders(); //Test4
	        for ( FamilyMember elder: elders ) {
	        	familyTree.printLineage(elder.getName());
	        }
	        fmr2.getDivorced();//Test4
	        
	        //Validates the actions performed on family members.
	        if (fmr1.getSpouse().getKey().equals(fmr9.getKey()) ){
	        	System.out.println("Test1 pass!");
	        }
	        else{
	        	System.out.println("Somthing wrong in marriage - fm1 doesn't" +
	        			"Know he's married to fmr9");
	        }
	        if (fmr2.getSpouse() == null ){
	        	System.out.println("Test2 pass!");
	        }
	        else{
	        	System.out.println("Somthing wrong in divorce");	        		
	        }
	        if (fmr0.getFather().getKey().equals(fmr1.getKey()) ){
	        	System.out.println("Test3 pass!");
	        }
	        else{
	        	System.out.println("Somthing wrong in Setting father" );
	        }
	        if (fmr3.getMother().getKey().equals(fmr9.getKey()) ){
	        	System.out.println("Test4 pass!");
	        }
	        else{
	        	System.out.println("Somthing wrong in Setting mother");
	        }
	        if (elders.size() == 4){
	            
	        	System.out.println("Test5 pass!");
	        }
	        else{
	            System.out.println(elders.size());
	        	System.out.println("Somthing wrong in elders calculations.");
	        }
		}
		
		
		
		catch (FamilyException e){
			System.out.println("Family error!");
		}
		catch (InvalidDateException e){
			System.out.println("Date error!");
        }
        
	}
	/**
	 * Main - running program.
	 * @param args Nothing.
	 */
	public static void main(String[] args) {
		setFamilyMemebrs();		
	}

}
